package za.co.EYEWTKAH.jmsProjects.openJmsClient;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

public class JMSMessageListener implements MessageListener {

    private int numReceived = 0;
    
    public int getNumReceived() {
        return numReceived;
    }

    public void onMessage(Message message) {
        if (message instanceof TextMessage) {
            try {
                ((TextMessage) message).getText();
                numReceived++;
            } catch (JMSException ex) {
                throw new RuntimeException(ex);
            }
        } else {
            throw new IllegalArgumentException("Message must be of type TextMessage");
        }
    }
}
